import java.util.*;

public class Main {

    //
    public int getDis (int[] A, int n) {
        int ret = 0;
        int min = A[0];
        for(int i = 1; i < n; i++){
            min = Math.min(min, A[i]);
            ret = Math.max(ret, A[i] - min);
        }
        return ret;
    }

    //
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), aim = in.nextInt();
        int[] arr = new int[n + 1];
        for(int i = 1; i <= n; i++){
            arr[i] = in.nextInt();
        }

        int[] dp = new int[aim + 1];
        Arrays.fill(dp, 0x3f3f3f3f);
        dp[0] = 0;

        for(int i = 1; i <= n; i++){
            for(int j = arr[i]; j <= aim; j++){
                dp[j] = Math.min(dp[j], dp[j - arr[i]] + 1);
            }
        }
        System.out.println(dp[aim] >= 0x3f3f3f3f ? -1 : dp[aim]);
    }

    //
    public static int n, l, r;
    public static char[] s;

    //找出字符种类在 [1, x] 之间的子串的个数
    public static long find(int x){
        int left = 0, right = 0;
        int[] hash = new int[26];
        int kinds = 0;
        long ret = 0;

        while(right < n){
            if(hash[s[right] - 'a']++ == 0) { kinds++;}
            while(kinds > x){
                if(hash[s[left] - 'a']-- == 1) { kinds--;}
                left++;
            }
            ret += right - left + 1;
            right++;
        }
        return ret;
    }

    public static void main2(String[] args){
        Scanner in = new Scanner(System.in);
        n = in.nextInt(); l = in.nextInt(); r = in.nextInt();
        s = in.next().toCharArray();

        System.out.println(find(r) - find(l - 1));
    }

    //
    public static void moveZeroes(int[] nums) {
        for(int cur = 0, dest = -1; cur < nums.length; cur++){
            if(nums[cur] != 0){
                dest++;
                int t = nums[cur];
                nums[cur] = nums[dest];
                nums[dest] = t;
            }
        }
    }

    public static void main3(String[] args) {
//        moveZeroes(new int[]{0,1,0,3,12});
        moveZeroes(new int[]{1, 2, 3, 4});
    }

    //
    public void duplicateZeros(int[] arr) {
        int cur = 0, zero = -1, n = arr.length;
        while(cur < n){
            if(arr[cur] == 0){
                zero += 2;
            }else{
                zero++;
            }

            if(zero >= n - 1) { break;}
            cur++;
        }

        if(zero == n){
            arr[n - 1] = 0;
            zero -= 2;
            cur--;
        }

        while(cur >= 0){
            if(arr[cur] == 0){
                arr[zero--] = 0;
                arr[zero--] = 0;
                cur--;
            }else{
                arr[zero--] = arr[cur--];
            }
        }
    }

    //
    public int f(int x){
        int ret = 0;
        while(x != 0){
            int t = x % 10;
            ret += t * t;
            x /= 10;
        }
        return ret;
    }

    public boolean isHappy(int n) {
        int cur = n, next = f(n);

        while(cur != next){
            cur = f(cur);
            next = f(f(next));
        }

        return cur == 1;
    }

    //
    public int maxArea(int[] height) {
        int left = 0, right = height.length - 1, v = 0;
        while(left < right){
            int t = (Math.min(height[left], height[right]) * (right - left));
            v = Math.max(v, t);

            if(height[left] < height[right]){
                left++;
            }else{
                right--;
            }
        }
        return v;
    }

    //
    public int triangleNumber(int[] nums) {
        Arrays.sort(nums);
        int ret = 0, n = nums.length;

        for(int i = n - 1; i >= 2; i--){
            int left = 0, right = i - 1;
            while(left < right){
                if(nums[left] + nums[right] > nums[i]){
                    ret += right - left;
                    right--;
                }else{
                    left++;
                }
            }
        }
        return ret;
    }

    //
    public int[] twoSum(int[] price, int target) {
        int left = 0, right = price.length - 1;
        while(left < right){
            int t = price[left] + price[right];
            if(t > target){
                right--;
            }else if(t < target){
                left++;
            }else{
                return new int[]{price[left], price[right]};
            }
        }
        return new int[]{};
    }

    //
    public List<List<Integer>> threeSum(int[] nums) {
        List<List<Integer>> list = new ArrayList<>();
        Arrays.sort(nums);
        int n = nums.length;

        for(int i = 0; i < n; ){
            int left = i + 1, right = n - 1, target = - nums[i];
            while(left < right){
                int t = nums[left] + nums[right];
                if(t > target){
                    right--;
                }else if(t < target){
                    left++;
                }else{
                    list.add(new ArrayList<>(Arrays.asList(nums[i], nums[left], nums[right])));
                    left++;
                    right--;
                    while(left < right && nums[left] == nums[left - 1]) { left++;}
                    while(left < right && nums[right] == nums[right + 1]) { right--;}
                }
            }
            i++;
            while(i < n && nums[i] == nums[i - 1]) { i++;}
        }
        return list;
    }
}
